﻿using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;

namespace Mars.GpuInstance
{
    [BurstCompile(FloatPrecision = FloatPrecision.Low, FloatMode = FloatMode.Fast)]
    public struct GPUAnimationCopyData : IJob
    {
        [ReadOnly] public NativeList<int> outputIndex;
        [ReadOnly] public NativeList<float4> animationData;
        [ReadOnly] public NativeList<float4> animatorControllerData;
        
        [WriteOnly] public NativeArray<float4> cullingAnimationData;
        [WriteOnly] public NativeArray<float4> cullingAnimatorControllerData;
        public void Execute()
        {
            var len = outputIndex.Length;
            for (int i = 0; i < len; i++)
            {
                var index = outputIndex[i];
                for (int j = 0; j < 2; j++)
                {
                    cullingAnimationData[i * 2 + j] = animationData[index * 2 + j];
                    cullingAnimatorControllerData[i * 2 + j] = animatorControllerData[index * 2 + j];
                }
            }
        }
    }
}
